package com.aaa.hospital.service.impl;

import com.aaa.hospital.mapper.KesMapper;
import com.aaa.hospital.pojo.domain.Kes;
import com.aaa.hospital.pojo.query.KesQuery;
import com.aaa.hospital.result.AjaxResult;
import com.aaa.hospital.service.KesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @Author: danghui
 * @Date: 2022/1/10 17:28
 * @Description: TODO
 */
@Service
public class KesServiceImpl implements KesService {

    @Autowired
    private KesMapper kesMapper;

    @Override
    public AjaxResult listAllKes() {
        List<Kes> kes = kesMapper.listAllKes();
        return AjaxResult.success(kes);
    }

    @Override
    public AjaxResult listKes(KesQuery query) {
        List<Kes> kes = kesMapper.listKes(query);
        Long aLong = kesMapper.listKesTotal(query);
        HashMap<Object, Object> data = new HashMap<>();
        data.put("currentData",kes);
        data.put("totalCount",aLong);
        return AjaxResult.success(data);
    }

    @Override
    public AjaxResult deleteKes(Integer id) {

        int i = kesMapper.deleteKes(id);
        if (i>0){
            return AjaxResult.success();
        }else {
            return AjaxResult.fail();
        }

    }

    @Override
    public AjaxResult addKes(Kes kes) {
        int i = kesMapper.addKes(kes);
        System.out.println(i+"******************");
        if (i>0){
            return AjaxResult.success();
        }else {
            return AjaxResult.fail();
        }
    }

    @Override
    public AjaxResult getKes(Integer id) {
        Kes kes = kesMapper.getKes(id);
        return AjaxResult.success(kes);
    }

    @Override
    public AjaxResult updateKes(Kes kes) {
        int i = kesMapper.updateKes(kes);
        System.out.println(i+"---------------");
        if (i>0){
            return AjaxResult.success();
        }
        return AjaxResult.fail();

    }
}
